{% extends "sys.html" %}

{% block tabs %}{{show_tabs()}}{% endblock %}

{% block clientscript %}
	{{super()}}
	<script>
		function edit_cfg(id){
		    $('#dlg').dialog({
						title: '系统配置管理',
						width: 370,
						height: 320,
						closed: false,
						cache: false,
						//href: '?op=bsp&id=90',
						modal: true
					});
				   $('#dlg').dialog('refresh','/edit_cfg/'+id);
		}
		function fmt_op(val,row){
			return "[<a href='javascript:void(0)' onclick='new_cfg("+row.id+")' >编辑</a>]" +
                "&nbsp;&nbsp;[<a href='javascript:void(0)' onclick='del_cfg("+row.id+")' >删除</a>]";
		}
		function new_cfg(id){
		    $('#dlg').dialog({
						title: '系统配置管理',
						width: 370,
						height: 320,
						closed: false,
						cache: false,
						//href: '?op=bsp&id=90',
						modal: true
					});
				   $('#dlg').dialog('refresh','/edit_cfg/'+id);
		}
		
		function del_cfg(id){
		     var msg="确认删除此配置吗？"
		         $.messager.confirm("确认", msg, function (r) {
		                if (r) {
		                    $.get("/del_cfg/"+id,function(data,status){
		                         $('#gri').datagrid('reload');
		                    });
		                    return true;
		                }
		            });
		            return false;
		}
	</script>
{% endblock clientscript %}

{% block work_content %}
<div id="tb" style="padding:3px">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="edit_cfg(0)">新增配置</a>
     </div>
    {% from "snippet.html" import render_field %}
    <div id="dlg" closed="true" class="easyui-dialog" data-options="buttons: [{
            text:'确定',
            iconCls:'icon-ok',
            handler:function(){
                $.ajax({
                    type: 'post',
                    url: $('#form_post').attr('action'),
                    data:$('#form_post').serialize(),
                    dataType: 'text',
                    success: function(data,textStatus){
                        if (data=='1'){
                            $('#gri').datagrid('reload');
                            $('#dlg').dialog('close');
                        } else {
                            $.messager.alert('错误',data,'error');
                        }

                    },
                    error: function(err){
                        //请求出错处理
                        $.messager.alert('错误','操作失败,请稍后重试!','error');
                    }
                });
            }
        },{

            text:'取消',
            iconCls:'icon-cancel',
            handler:function(){
                $('#dlg').dialog('close');
            }
        }]">
    </div>

    <div class='grid'>
	    <table id="gri" class="easyui-datagrid" style="height:600px"
	            url="{{ url_for('qry_config_data') }}"
	            title=""
	            toolbar="#tb"
	            singleSelect="true"
	            pageSize="20"
	            fitColumns="true"
	            rownumbers="true" pagination="true">
	        <thead>
	            <tr>
	                <th field="key" width="50">key</th>
                   <th field="value" width="40" >value</th>
	                <th field="descript" width="40" >descript</th>
						 <th field="created_date" width="20" formatter="fmt_op" >操作</th>
	            </tr>
	        </thead>
	    </table>
    </div>
{% endblock %}